/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb.session;

import clases.domain.*;
import clases.domain.services.EmpleadoService;
import clases.domain.services.MantenedorBodegaService;
import clases.domain.services.MantenedorFabricaService;
import clases.domain.services.MantenedorModeloService;
import clases.domain.services.MantenedorPiezaService;
import clases.domain.services.MantenedorUnidadService;
import clases.domain.services.MantenedorVersionService;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJBException;
import javax.ejb.Stateless;

/**
 *
 * @author Diego
 */
@Stateless
public class MantenedoresBean implements MantenedoresLocal {

    @Override
    public boolean insertPiezas(Pieza pieza) {
        MantenedorPiezaService piezaService = new MantenedorPiezaService();
        boolean inserta = false;
        try {
            inserta = piezaService.insertPiezas(pieza);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return inserta;

    }

    @Override
    public boolean updatePiezas(Pieza pieza) {
        MantenedorPiezaService piezaService = new MantenedorPiezaService();
        boolean update = false;
        try {
            update = piezaService.updatePiezas(pieza);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return update;
    }

    @Override
    public boolean deletePiezas(Pieza pieza) throws EJBException {
        MantenedorPiezaService piezaService = new MantenedorPiezaService();
        boolean delete = false;
        try {
            delete = piezaService.deletePiezas(pieza);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return delete;
    }

    @Override
    public List<Pieza> getListPiezas() throws EJBException {
        MantenedorPiezaService piezaService = new MantenedorPiezaService();
        List<Pieza> listaPiezas = new ArrayList();
        try {
            listaPiezas = piezaService.getListPiezas(null);
        } catch (Exception e) {
        }
        return listaPiezas;
    }

    public List<Pieza> getListPiezasByVersion(int numVersion) throws EJBException {
        MantenedorPiezaService piezaService = new MantenedorPiezaService();
        List<Pieza> listaPiezas = new ArrayList();
        try {
            listaPiezas = piezaService.getListPiezasByVersion(numVersion);
        } catch (Exception e) {
            System.out.println("Error");
        }
        return listaPiezas;
    }

    @Override
    public boolean insertModelo(Modelo modelo) throws EJBException {
        boolean inserta = false;
        MantenedorModeloService modService = new MantenedorModeloService();
        try {
            inserta = modService.insertModelo(modelo);
        } catch (Exception e) {
            System.out.println("Error al insertar fabrica");
        }
        return inserta;
    }

    @Override
    public boolean updateModelo(Modelo modelo) throws EJBException {
        MantenedorModeloService modService = new MantenedorModeloService();
        boolean update = false;
        try {
            update = modService.updateModelo(modelo);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return update;
    }

    @Override
    public boolean deleteModelo(Modelo modelo) throws EJBException {
        MantenedorModeloService modService = new MantenedorModeloService();
        boolean delete = false;
        try {
            delete = modService.deleteModelo(modelo);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return delete;
    }

    @Override
    public List<Modelo> getListModelos() throws EJBException {
        MantenedorModeloService modeloService = new MantenedorModeloService();
        List<Modelo> listaModelos = new ArrayList<Modelo>();
        try {
            listaModelos = modeloService.getListAllModelos();
        } catch (Exception e) {
        }
        return listaModelos;
    }

    @Override
    public boolean insertVersion(Version version) throws EJBException {
        boolean inserta = false;
        MantenedorVersionService versionService = new MantenedorVersionService();
        try {
            inserta = versionService.insertVersion(version);
        } catch (Exception e) {
            System.out.println("Error al insertar version");
        }
        return inserta;
    }

    @Override
    public boolean updateVersion(Version version) throws EJBException {
        MantenedorVersionService versionService = new MantenedorVersionService();
        boolean update = false;
        try {
            update = versionService.updateVersion(version);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return update;
    }

    @Override
    public boolean deleteVersion(Version version) throws EJBException {
        MantenedorVersionService versionService = new MantenedorVersionService();
        boolean delete = false;
        try {
            delete = versionService.deleteVersion(version);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return delete;
    }

    @Override
    public List<Version> getListVersiones() throws EJBException {
         MantenedorVersionService versionService = new MantenedorVersionService();
         List<Version> listaVersion= new ArrayList<Version>();
        try {
            listaVersion = versionService.getListVersion();
        } catch (Exception e) {
        }
        return listaVersion;
    }

    @Override
    public boolean insertFabrica(Fabrica fabrica) throws EJBException {
        boolean inserta = false;
        MantenedorFabricaService fabService = new MantenedorFabricaService();
        try {
            inserta = fabService.insertFabrica(fabrica);
        } catch (Exception e) {
            System.out.println("Error al insertar fabrica");
        }
        return inserta;

    }

    @Override
    public boolean updateFabrica(Fabrica fabrica) throws EJBException {
        MantenedorFabricaService fabService = new MantenedorFabricaService();
        boolean update = false;
        try {
            update = fabService.updateFabrica(fabrica);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return update;
    }

    @Override
    public boolean deleteFabrica(Fabrica fabrica) throws EJBException {
        MantenedorFabricaService fabService = new MantenedorFabricaService();
        boolean delete = false;
        try {
            delete = fabService.deleteFabrica(fabrica);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return delete;
    }

    @Override
    public List<Fabrica> getListFabricas() throws EJBException {
        MantenedorFabricaService fabricaService = new MantenedorFabricaService();
        List<Fabrica> listaFabricas = new ArrayList();
        try {
            listaFabricas = fabricaService.getListFabricas();
        } catch (Exception e) {
            System.out.println("Error");
        }
        return listaFabricas;
    }

    @Override
    public boolean insertBodega(Bodega bodega) throws EJBException {
        MantenedorBodegaService bodegaService = new MantenedorBodegaService();
        boolean insert = false;
        try {
            insert = bodegaService.insertBodega(bodega);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return insert;
    }

    @Override
    public boolean updateBodega(Bodega bodega) throws EJBException {
        MantenedorBodegaService bodegaService = new MantenedorBodegaService();
        boolean update = false;
        try {
            update = bodegaService.updateBodega(bodega);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return update;
    }

    @Override
    public boolean deleteBodega(Bodega bodega) throws EJBException {
        MantenedorBodegaService bodegaService = new MantenedorBodegaService();
        boolean delete = false;
        try {
            delete = bodegaService.deleteBodega(bodega);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return delete;
    }

    @Override
    public List<Bodega> getListBodegas() throws EJBException {
        MantenedorBodegaService bodegaService = new MantenedorBodegaService();
        List<Bodega> listaBodega = new ArrayList();
        try {
            listaBodega = bodegaService.getListBodegas();
        } catch (Exception e) {
            System.out.println("Error");
        }
        return listaBodega;
    }

    @Override
    public boolean insertUnidad(Unidad unidad) throws EJBException {
        MantenedorUnidadService unidadService = new MantenedorUnidadService();
        boolean insert = false;
        try {
            insert = unidadService.insertUnidad(unidad);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return insert;
    }

    @Override
    public boolean updateUnidad(Unidad unidad) throws EJBException {
        MantenedorUnidadService unidadService = new MantenedorUnidadService();
        boolean update = false;
        try {
            update = unidadService.updateUnidad(unidad);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return update;
    }

    @Override
    public boolean deleteUnidad(Unidad unidad) throws EJBException {
        MantenedorUnidadService unidadService = new MantenedorUnidadService();
        boolean delete = false;
        try {
            delete = unidadService.deleteUnidad(unidad);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return delete;
    }

    @Override
    public List<Unidad> getListUnidad() throws EJBException {
        MantenedorUnidadService unidadService = new MantenedorUnidadService();
        List<Unidad> listaUnidad = new ArrayList();
        try {
            listaUnidad = unidadService.getListUnidad();
        } catch (Exception e) {
            System.out.println("Error");
        }
        return listaUnidad;
    }

    @Override
    public Empleado login(Empleado empleado) throws EJBException {
        EmpleadoService empService=new EmpleadoService();
        Empleado emp=new Empleado();
        try {
            emp=empService.login(empleado);
        } catch (Exception e) {
        }
        return emp;
    }

    @Override
    public boolean insertarEmpleado(Empleado empleado) throws EJBException {
        EmpleadoService empService=new EmpleadoService();
        boolean insert = false;
        try {
            insert = empService.insertEmpleado(empleado);
        } catch (Exception ex) {
            ex.printStackTrace(); 
        }
        return insert;
    }

    @Override
    public boolean updateEmpleado(Empleado empleado) throws EJBException {
        EmpleadoService empService=new EmpleadoService();
        boolean update = false;
        try {
            update = empService.updateEmpleado(empleado);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return update;
    }

    @Override
    public boolean deleteEmpleado(Empleado empleado) throws EJBException {
        EmpleadoService empService=new EmpleadoService();
        boolean delete = false;
        try {
            delete = empService.deleteEmpleado(empleado);
        } catch (Exception ex) {
            Logger.getLogger(MantenedoresBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return delete;
    }
}
